package spittr.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


@Configuration
@EnableWebMvc
@ComponentScan("spittr.web")
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views");//在查找视图文件时会加上此前缀
        resolver.setSuffix(".jsp");//在查找视图文件后会加上此后缀
        return resolver;
    }


    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        /**
         * Enable forwarding to the "default" Servlet.
         * <p>When this method is used the {@link DefaultServletHttpRequestHandler}
         * will try to autodetect the "default" Servlet name. Alternatively, you can
         * specify the name of the default Servlet via {@link #enable(String)}.
         * @see DefaultServletHttpRequestHandler
         */
        configurer.enable();//对静态文件的请求处理转发到servlet容器本身，而不是DispatcherServlet来处理
    }
}
